<template>
  <div class="content">
    <div class="reporting-main">
      <div class="hd">
        <steps :step="1" :revise="isEditInfos" :editTitle="editTitle"></steps>
      </div>
      <div class="bd">
        <notice :title="alertTitle"></notice>
        <van-form
          @submit="submitForm"
          class="van-cell-input_right"
          scroll-to-error
        >
          <!-- 学生信息 -->
          <div class="reporting-list module">
            <div class="list-hd">
              <h3 class="title"><i class="icon icon_stu"></i>学生信息</h3>
              <div class="slide" @click="slideModule(1)">
                <span>{{ isSlide1 ? "收起" : "展开" }}</span>
                <!-- <i class="icon" :class="{ 'icon-up': isSlide1 }"></i> -->
                <van-icon
                  class="icon"
                  :name="isSlide1 ? 'arrow-up' : 'arrow-down'"
                />
              </div>
            </div>
            <div class="list-bd" v-if="isSlide1">
              <!-- 是否有户口 -->
              <van-cell
                title="是否有户口"
                :value="stuList.ogState == '0' ? '无户口' : '有户口'"
                class="van-cell_value3 padr fle"
              />
              <!-- 学生姓名 -->
              <van-field
                class="padr"
                required
                label="学生姓名"
                v-model.trim="ruleForm.name"
                name="name"
                placeholder="请输入学生姓名"
                :rules="[
                  { required: true, message: '请输入学生姓名' },
                  {
                    pattern: /(^.{1,100}$)/,
                    message: '输入长度在100以内',
                  },
                ]"
              >
              </van-field>
              <!-- 身份证号 -->
              <van-field
                class="padr"
                required
                v-if="ruleForm.regType != 'reg10'"
                label="身份证号"
                v-model="ruleForm.idno"
                name="idno"
                placeholder="请输入身份证号"
                :rules="[
                  {
                    pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
                    required: true,
                    message: '请输入正确的证件号码',
                  },
                ]"
                @change="idChange"
                disabled
              >
              </van-field>
              <!-- 证件号 -->
              <van-field
                class="padr"
                required
                v-else
                label="证件号"
                v-model="ruleForm.idno"
                name="idno"
                placeholder="请输入证件号"
                :rules="[{ required: true, message: '请输入证件号' }]"
                disabled
              >
              </van-field>
              <!-- 出生日期 -->
              <van-field
                required
                label="出生日期"
                v-model="ruleForm.birth"
                name="birth"
                is-link
                placeholder="请选择出生日期"
                @focus="showBirthChoice = true"
                :rules="[{ required: true, message: '请选择出生日期' }]"
                disabled
              >
              </van-field>
              <van-popup
                v-model="showBirthChoice"
                position="bottom"
                :style="{ height: '30%' }"
              >
                <van-datetime-picker
                  v-model="currentDate"
                  type="date"
                  title="选择年月日"
                  @cancel="showBirthChoice = false"
                  @confirm="confirmBirth()"
                />
              </van-popup>
              <!-- 性别 -->
              <van-field
                required
                label="性别"
                v-model="ruleForm.gender"
                name="gender"
                is-link
                placeholder="请选择学生性别"
                @focus="showSexChoice = true"
                :rules="[{ required: true, message: '请选择学生性别' }]"
                disabled
                readonly
              >
              </van-field>
              <van-action-sheet
                v-model="showSexChoice"
                :round="false"
                :actions="sexes"
                @select="onSelectSex"
              ></van-action-sheet>
              <!-- 登录密码 -->
              <van-field
                required
                label="登录密码"
                right-icon="yanjing"
                v-model="ruleForm.pwd"
                :type="password"
                name="pwd"
                placeholder="密码由6-20位数字或字母或特殊字符中的两种组成"
                :rules="[
                  { required: true, message: '请填写密码' },
                  {
                    pattern: /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)^.{6,20}$/,
                    message:
                      '密码格式不正确，请输入由6-20位数字或字母或特殊字符中的两种组成的密码',
                  },
                ]"
              >
                <van-icon
                  class="iconfont iconyanjing"
                  class-prefix="icon"
                  slot="right-icon"
                  name="yanjing"
                  @click="showPwd"
                ></van-icon>
              </van-field>
              <!-- 户籍类型 -->
              <van-field
                required
                label="户籍类型"
                v-model="ogType"
                name="ogType"
                is-link
                placeholder="请选择户籍类型"
                @focus="showOgTypeChoice = true"
                :rules="[{ required: true, message: '请选择户籍类型' }]"
                readonly
              >
              </van-field>
              <van-action-sheet
                v-model="showOgTypeChoice"
                :round="false"
                :actions="ogTypes"
                @select="onSelectOgType"
              ></van-action-sheet>

              <!-- 民族 -->
              <van-field
                required
                label="民族"
                v-model="nation"
                name="nation"
                is-link
                placeholder="请选择民族"
                @focus="showNationChoice = true"
                :rules="[{ required: true, message: '请选择民族' }]"
                readonly
              >
              </van-field>
              <van-action-sheet
                v-model="showNationChoice"
                :round="false"
                :actions="nations"
                @select="onSelectNation"
                :style="{ height: '50%' }"
              ></van-action-sheet>
              <!-- 手机号码 -->
              <van-field
                class="padr"
                required
                label="手机号码"
                v-model="ruleForm.phone"
                name="phone"
                placeholder="接收短信使用"
                :rules="[
                  {
                    pattern: /^1[34578]\d{9}$/,
                    required: true,
                    message: '请输入正确的手机号码',
                  },
                ]"
              >
              </van-field>
              <!-- 健康状况 -->
              <van-field
                required
                label="健康状况"
                v-model="healthType"
                name="healthType"
                is-link
                placeholder="请选择健康状况"
                @focus="showHealthTypeChoice = true"
                :rules="[{ required: true, message: '请选择健康状况' }]"
                readonly
              >
              </van-field>
              <van-action-sheet
                v-model="showHealthTypeChoice"
                :round="false"
                :actions="healthTypes"
                @select="onSelectHealthType"
              ></van-action-sheet>
              <!-- 残疾类型 -->
              <van-field
                label="残疾类型"
                v-model="disableType"
                name="disableType"
                is-link
                placeholder="请选择残疾类型"
                @focus="showDisableTypeChoice = true"
                :disabled="ruleForm.healthType != '残疾'"
                readonly
              >
              </van-field>
              <van-action-sheet
                v-model="showDisableTypeChoice"
                :round="false"
                :actions="disableTypes"
                @select="onSelectDisableType"
              ></van-action-sheet>
            </div>
          </div>
          <!-- 入学信息 -->
          <div class="reporting-list module">
            <div class="list-hd">
              <h3 class="title"><i class="icon icon_toschool"></i>入学信息</h3>
              <div class="slide" @click="slideModule(2)">
                <span>{{ isSlide2 ? "收起" : "展开" }}</span>
                <!-- <i class="icon" :class="{ 'icon-up': isSlide1 }"></i> -->
                <van-icon
                  class="icon"
                  :name="isSlide2 ? 'arrow-up' : 'arrow-down'"
                />
              </div>
            </div>
            <div class="list-bd" v-if="isSlide2">
              <!-- 入学类型 -->
              <van-cell
                title="入学类型"
                :value="regType"
                class="van-cell_value3 fle padr"
              />

              <!-- 实际居住产权类型 -->
              <van-field
                class="fle"
                required
                readonly
                clickable
                is-link
                name="ogRegion"
                v-model="houseType"
                label="实际居住产权类型"
                placeholder="请选择"
                :rules="[{ required: true, message: '请选择实际居住产权类型' }]"
                @click="showHouseTypeChoice = true"
              />
              <van-action-sheet
                v-model="showHouseTypeChoice"
                :round="false"
                :actions="houseTypes"
                @select="onSelectHouseType"
              ></van-action-sheet>

              <!-- 现居住区县 -->
              <van-field
                class="fle1"
                required
                :label="
                  ruleForm.regType == 'reg1' ? '户籍地址区县' : '现居住区县'
                "
                v-model="regionCode"
                name="regionCode"
                is-link
                placeholder="请选择区县"
                @focus="showRegionCodeChoice = true"
                :rules="[{ required: true, message: '请选择区县' }]"
                readonly
              >
              </van-field>
              <van-action-sheet
                v-model="showRegionCodeChoice"
                :round="false"
                :actions="liveBlockLists"
                @select="onSelectLiveBlock"
                :style="{ height: '30%' }"
              ></van-action-sheet>
              <!-- 现居住街道 -->
              <van-field
                class="fle1"
                required
                :label="
                  ruleForm.regType == 'reg1' ? '户籍地址街道' : '现居住街道'
                "
                v-model="liveStreet"
                name="disableType"
                is-link
                placeholder="请选择街道"
                @focus="onSelectStreet"
                :rules="[{ required: true, message: '请选择街道' }]"
                readonly
              >
              </van-field>
              <van-action-sheet
                v-model="showLiveStreetChoice"
                :round="false"
                :actions="liveStreets"
                @select="onSelectLiveStreet"
                :style="{ height: '30%' }"
              ></van-action-sheet>

              <!-- 现居住小区 -->
              <van-field
                class="fle1"
                required
                :label="
                  ruleForm.regType == 'reg1' ? '户籍地址小区' : '现居住小区'
                "
                v-model="liveCommunity"
                name="liveCommunity"
                is-link
                placeholder="请选择小区"
                @focus="onSelectCommunity"
                :rules="[{ required: true, message: '请选择小区' }]"
                readonly
              >
              </van-field>
              <van-action-sheet
                v-model="showLiveCommunityChoice"
                :round="false"
                :actions="liveCommunitys"
                @select="onSelectLiveCommunity"
                :style="{ height: '30%' }"
              ></van-action-sheet>
              <!-- 现详细地址 -->
              <van-field
                class="wid100 padr"
                required
                :label="
                  ruleForm.regType == 'reg1' ? '户籍详细地址' : '现详细地址'
                "
                v-model.trim="ruleForm.address"
                name="address"
                placeholder="楼栋-单元-房号，1-2-302"
                :rules="[
                  { required: true, message: '请输入详细地址' },
                  {
                    pattern: /(^.{1,100}$)/,
                    message: '输入长度在100以内',
                  },
                ]"
              >
              </van-field>
              <!-- 户籍所在地 -->
              <van-field
                v-if="ruleForm.regType != 'reg10'"
                class="fle1"
                required
                readonly
                clickable
                is-link
                name="ogRegion"
                :value="ruleForm.ogRegion"
                :label="
                  ruleForm.regType == 'reg1' ? '当前居住地址' : '户籍地址'
                "
                placeholder="点击选择省市区"
                :rules="[{ required: true, message: '请选择省市区' }]"
                @click="showArea = true"
              />
              <van-popup
                v-model="showArea"
                position="bottom"
                :style="{ height: '50%' }"
              >
                <van-area
                  :area-list="areaList"
                  @confirm="onConfirmArea"
                  @cancel="showArea = false"
                />
              </van-popup>
              <!-- 户籍详细地址 -->
              <van-field
                class="wid100 padr fle1"
                v-if="ruleForm.regType != 'reg10'"
                required
                :label="
                  ruleForm.regType == 'reg1' ? '当前详细地址' : '户籍详细地址'
                "
                v-model.trim="ruleForm.ogAddress"
                name="ogAddress"
                placeholder="请输入详细地址"
                :rules="[
                  { required: true, message: '请输入详细地址' },
                  {
                    pattern: /(^.{1,100}$)/,
                    message: '输入长度在100以内',
                  },
                ]"
              >
              </van-field>
              <van-field
                v-else
                class="wid100 padr fle1"
                required
                :label="
                  ruleForm.regType == 'reg1' ? '当前详细地址' : '户籍详细地址'
                "
                v-model.trim="ruleForm.foreignAddress"
                name="foreignAddress"
                placeholder="请输入户籍地址"
                :rules="[
                  { required: true, message: '请输入户籍地址' },
                  {
                    pattern: /(^.{1,100}$)/,
                    message: '输入长度在100以内',
                  },
                ]"
              >
              </van-field>
              <!-- 监护人工作单位 -->
              <van-field
                v-if="ruleForm.regType == 'reg9'"
                class="wid100 padr fle"
                required
                label="监护人工作单位"
                v-model.trim="ruleForm.parWork"
                name="parWork"
                placeholder="请输入工作单位"
                :rules="[
                  { required: true, message: '请输入工作单位' },
                  {
                    pattern: /(^.{1,100}$)/,
                    message: '输入长度在100以内',
                  },
                ]"
              >
              </van-field>
              <!-- 工作单位电话 -->
              <van-field
                v-if="ruleForm.regType == 'reg9'"
                class="wid100 padr fle"
                required
                label="工作单位电话"
                v-model.trim="ruleForm.parWorkTel"
                name="parWorkTel"
                placeholder="请输入工作单位电话"
                :rules="[
                  { required: true, message: '请输入工作单位电话' },
                  {
                    pattern: /(^.{1,100}$)/,
                    message: '输入长度在100以内',
                  },
                ]"
              >
              </van-field>
              <p
                v-if="ruleForm.regType == 'reg9'"
                class="el-form-infos"
                style="padding-left: 10px; text-align: left"
              >
                请填写单位座机，不要填写手机号
              </p>
              <!-- 意向学校1 -->
              <van-field
                v-if="ruleForm.regType == 'reg9'"
                required
                readonly
                label="意向学校1"
                v-model="wishSchool1"
                name="wishSchool1"
                is-link
                placeholder="请选择意向学校1"
                @focus="showWishSchool1Choice = true"
                :rules="[{ required: true, message: '请选择意向学校1' }]"
              >
              </van-field>
              <van-action-sheet
                v-model="showWishSchool1Choice"
                :round="false"
                :actions="wishSchools"
                @select="onSelectWishSchool1"
                :style="{ height: '40%' }"
              ></van-action-sheet>
              <!-- 意向学校2 -->
              <van-field
                v-if="ruleForm.regType == 'reg9'"
                required
                readonly
                label="意向学校2"
                v-model="wishSchool2"
                name="wishSchool2"
                is-link
                placeholder="请选择意向学校2"
                @focus="showWishSchool2Choice = true"
                :rules="[{ required: true, message: '请选择意向学校2' }]"
              >
              </van-field>
              <van-action-sheet
                v-model="showWishSchool2Choice"
                :round="false"
                :actions="wishSchools"
                @select="onSelectWishSchool2"
                :style="{ height: '40%' }"
              ></van-action-sheet>
              <!-- 意向学校3 -->
              <van-field
                v-if="ruleForm.regType == 'reg9'"
                required
                readonly
                label="意向学校3"
                v-model="wishSchool3"
                name="wishSchool3"
                is-link
                placeholder="请选择意向学校3"
                @focus="showWishSchool3Choice = true"
                :rules="[{ required: true, message: '请选择意向学校2' }]"
              >
              </van-field>
              <van-action-sheet
                v-model="showWishSchool3Choice"
                :round="false"
                :actions="wishSchools"
                @select="onSelectWishSchool3"
                :style="{ height: '40%' }"
              ></van-action-sheet>
            </div>
          </div>
          <!-- 其他信息 -->
          <div class="reporting-list module" v-if="oilShow == '1'">
            <div class="list-hd">
              <h3 class="title"><i class="icon icon_other"></i>其他信息</h3>
              <div class="slide" @click="slideModule(3)">
                <span>{{ isSlide3 ? "收起" : "展开" }}</span>
                <!-- <i class="icon" :class="{ 'icon-up': isSlide1 }"></i> -->
                <van-icon
                  class="icon"
                  :name="isSlide3 ? 'arrow-up' : 'arrow-down'"
                />
              </div>
            </div>
            <div class="list-bd" v-if="isSlide3">
              <!-- 石油系统子女 -->
              <van-field
                class="wid100"
                label="石油系统子女"
                v-model="oilType"
                name="oilType"
                is-link
                placeholder="请选择"
                @focus="showOilTypeChoice = true"
                readonly
              >
              </van-field>
              <van-action-sheet
                v-model="showOilTypeChoice"
                :round="false"
                :actions="oilTypes"
                @select="onSelectOilType"
                @cancel="onCancelOilTypeChoice"
                cancel-text="取消"
              ></van-action-sheet>
              <p
                class="el-form-infos"
                style="padding-left: 10px; text-align: left"
              >
                石油系统子女选择，其他人请不要选择
              </p>
              <!-- 选择学校 -->
              <van-field
                label="选择学校"
                v-model="oilSchool"
                name="selectSchool"
                is-link
                placeholder="请选择"
                @focus="showSelectOilSchoolChoice = true"
                :disabled="ruleForm.oilType ? false : true"
                readonly
              >
              </van-field>
              <van-action-sheet
                v-model="showSelectOilSchoolChoice"
                :round="false"
                :actions="oilSchoolLists"
                @select="onSelectOilSchool"
              ></van-action-sheet>
            </div>
          </div>
          <!-- 监护人信息 -->
          <div class="reporting-list module">
            <div class="list-hd">
              <h3 class="title"><i class="icon icon_par"></i>监护人信息</h3>
              <div class="slide" @click="slideModule(4)">
                <span>{{ isSlide4 ? "收起" : "展开" }}</span>
                <!-- <i class="icon" :class="{ 'icon-up': isSlide1 }"></i> -->
                <van-icon
                  class="icon"
                  :name="isSlide4 ? 'arrow-up' : 'arrow-down'"
                />
              </div>
            </div>
            <div class="list-bd" v-if="isSlide4">
              <!-- 监护人1 -->
              <van-field
                class="wid100 padr"
                required
                label="监护人1姓名"
                v-model.trim="ruleForm.parName"
                name="parName"
                placeholder="请输入监护人1姓名"
                :rules="[
                  { required: true, message: '请输入监护人姓名' },
                  {
                    pattern: /(^.{1,100}$)/,
                    message: '输入长度在100以内',
                  },
                ]"
              >
              </van-field>
              <van-field
                class="padr"
                required
                :label="
                  ruleForm.regType == 'reg10' || ruleForm.regType == 'reg9'
                    ? '证件号'
                    : '身份证号'
                "
                v-model.trim="ruleForm.parIdno"
                name="parIdno"
                placeholder="请输入身份证号/证件号"
                :rules="
                  ruleForm.regType == 'reg10' || ruleForm.regType == 'reg9'
                    ? [
                        {
                          required: true,
                          message: '请输入证件号',
                        },
                        {
                          pattern: /(^.{1,100}$)/,
                          message: '输入长度在100以内',
                        },
                      ]
                    : [
                        {
                          required: true,
                          message: '请输入身份证号',
                        },
                        {
                          pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
                          message: '请输入正确的身份证号',
                        },
                      ]
                "
              >
              </van-field>
              <van-field
                class="padr"
                required
                label="联系电话"
                v-model="ruleForm.parPhone"
                name="parPhone"
                placeholder="请输入联系电话"
                :rules="[
                  {
                    pattern: /^1[34578]\d{9}$/,
                    required: true,
                    message: '请输入正确的手机号码',
                  },
                ]"
              >
              </van-field>
              <van-field
                required
                label="与学生关系"
                v-model="parRlat"
                name="parRlat"
                is-link
                placeholder="请选择学生关系"
                @focus="showParRlatChoice = true"
                :rules="[{ required: true, message: '请选择学生关系' }]"
                readonly
              >
              </van-field>
              <van-action-sheet
                v-model="showParRlatChoice"
                :round="false"
                :actions="parRlats"
                @select="onSelectParRlat"
              ></van-action-sheet>
              <!-- 监护人2 -->
              <van-field
                class="wid100 padr"
                label="监护人2姓名"
                v-model.trim="ruleForm.parName2"
                name="parName2"
                placeholder="请输入监护人2姓名"
                @blur="checkPar"
                :error-message="errMsg.errParName2"
              >
              </van-field>
              <van-field
                class="padr"
                :label="
                  ruleForm.regType == 'reg10' || ruleForm.regType == 'reg9'
                    ? '证件号'
                    : '身份证号'
                "
                v-model.trim="ruleForm.parIdno2"
                name="parIdno2"
                placeholder="请输入身份证号/证件号"
                @blur="checkPar"
                :error-message="errMsg.errParIdno2"
              >
              </van-field>
              <van-field
                class="padr"
                label="联系电话"
                v-model="ruleForm.parPhone2"
                name="parPhone2"
                placeholder="请输入联系电话"
                @blur="checkPar"
                :error-message="errMsg.errParPhone2"
              >
              </van-field>
              <van-field
                label="与学生关系"
                v-model="parRlat2"
                name="parRlat2"
                is-link
                placeholder="请选择学生关系"
                @focus="showParRlat2Choice = true"
                readonly
              >
              </van-field>
              <van-action-sheet
                v-model="showParRlat2Choice"
                :round="false"
                :actions="parRlats"
                @select="onSelectParRlat2"
                @cancel="onCancelParRlat2"
                cancel-text="取消"
              ></van-action-sheet>
            </div>
          </div>
          <div class="form-btn" v-if="verify.res != -1">
            <van-button block type="info" native-type="submit">{{
              isEditInfos ? "确认修改" : "下一步"
            }}</van-button>
          </div>
          <div class="no-edit" v-else>
            <van-icon name="warning" />{{ verify.msg }}
          </div>
        </van-form>
      </div>
    </div>
  </div>
</template>
<script>
import { Toast } from "vant";
import Steps from "../components/Steps";
import Notice from "../components/Notice";
import { formatDate } from "../utils/formatdate.js";
import { getAnalysisIdCard } from "../utils/util";
import { getVerify } from "../utils/api";
import localDb from "../utils/localDb";
import areaList from "../assets/js/area.js";
export default {
  name: "basicinfo",
  components: {
    Steps,
    Notice,
  },
  data() {
    return {
      ruleForm: {
        ogState: "1", //是否有户口
        name: "", //学生姓名
        idno: "", //学生身份证
        birth: "", //出生日期
        gender: "", //性别
        pwd: "", //登录密码
        ogType: "", //户籍类型
        nation: "", //民族
        phone: "", //手机号码
        healthType: "", //健康状况
        disableType: "", //残疾类型
        regType: 0, //入学类型
        houseType: "", //监护人是否有房

        regionCode: "", // 户籍区县/居住区县
        street: "", //户籍街道/居住街道
        community: "", //户籍小区/居住小区
        address: "", //户籍详细地址/居住详细地址
        ogRegion: "", //户籍所在省市区县
        ogAddress: "", // 户籍所在详细地址
        foreignAddress: "", //外籍户籍地址
        parWork: "", //工作单位
        parWorkTel: "", //工作单位电话

        wishSchool1: 0, // 意向学校1
        wishSchool2: 0,
        wishSchool3: 0,
        oilType: "", //是否是石油系统子女
        oilSchool: 0, //石油系统子女所选学校

        parName: "", //监护人1姓名
        parIdno: "", //监护人1身份证号
        parPhone: "", //监护人1联系电话
        parRlat: "", //监护人1生源关系
        parName2: "", //监护人2姓名
        parIdno2: "", //监护人2身份证号
        parPhone2: "", //监护人2联系电话
        parRlat2: "", //监护人2生源关系
      },
      isEditInfos: false, //是否是修改页面
      editTitle: "",
      stuList: {},
      isSlide1: true, //是否显示学生信息
      isSlide2: false, //是否显示入学信息
      isSlide3: false, //是否显示其他信息
      isSlide4: false, //是否显示监护人信息
      isPwd: true, //是否显示密码
      password: "password", //密码输入框类型

      regType: "", // 入学类型
      showOgTypeChoice: false, //是否显示户籍类型选项
      ogType: "", //当前选中的户籍类型
      ogTypes: [
        //户籍类型列表
        { name: "非农户口", value: "0" },
        { name: "农业户口", value: "1" },
      ],
      showBirthChoice: false, //显示日期选择
      currentDate: new Date(), //当前选中的出生日期
      showSexChoice: false, //显示性别选择
      sexes: [
        //性别列表
        { name: "男" },
        { name: "女" },
      ],
      showNationChoice: false, //是否显示民族选项
      nation: "", //当前选中的民族
      nations: [
        { id: 1, name: "汉族" },
        { id: 2, name: "蒙古族" },
        { id: 3, name: "回族" },
        { id: 4, name: "藏族" },
        { id: 5, name: "维吾尔族" },
        { id: 6, name: "苗族" },
        { id: 7, name: "彝族" },
        { id: 8, name: "壮族" },
        { id: 9, name: "布依族" },
        { id: 10, name: "朝鲜族" },
        { id: 11, name: "满族" },
        { id: 12, name: "侗族" },
        { id: 13, name: "瑶族" },
        { id: 14, name: "白族" },
        { id: 15, name: "土家族" },
        { id: 16, name: "哈尼族" },
        { id: 17, name: "哈萨克族" },
        { id: 18, name: "傣族" },
        { id: 19, name: "黎族" },
        { id: 20, name: "傈僳族" },
        { id: 21, name: "佤族" },
        { id: 22, name: "畲族" },
        { id: 23, name: "高山族" },
        { id: 24, name: "拉祜族" },
        { id: 25, name: "水族" },
        { id: 26, name: "东乡族" },
        { id: 27, name: "纳西族" },
        { id: 28, name: "景颇族" },
        { id: 29, name: "柯尔克孜族" },
        { id: 30, name: "土族" },
        { id: 31, name: "达翰尔族" },
        { id: 32, name: "么佬族" },
        { id: 33, name: "羌族" },
        { id: 34, name: "布朗族" },
        { id: 35, name: "撒拉族" },
        { id: 36, name: "毛南族" },
        { id: 37, name: "仡佬族" },
        { id: 38, name: "锡伯族" },
        { id: 39, name: "阿昌族" },
        { id: 40, name: "普米族" },
        { id: 41, name: "塔吉克族" },
        { id: 42, name: "怒族" },
        { id: 43, name: "乌孜别克族" },
        { id: 44, name: "俄罗斯族" },
        { id: 45, name: "鄂温克族" },
        { id: 46, name: "德昂族" },
        { id: 47, name: "保安族" },
        { id: 48, name: "裕固族" },
        { id: 49, name: "京族" },
        { id: 50, name: "塔塔尔族" },
        { id: 51, name: "独龙族" },
        { id: 52, name: "鄂伦春族" },
        { id: 53, name: "赫哲族" },
        { id: 54, name: "门巴族" },
        { id: 55, name: "珞巴族" },
        { id: 56, name: "基诺族" },
      ], //民族
      showHealthTypeChoice: false, //是否显示健康状况选项
      healthType: "", //当前选中的健康状况
      healthTypes: [
        //健康状况列表
        { name: "良好", value: "良好" },
        { name: "残疾", value: "残疾" },
      ],
      showDisableTypeChoice: false, //是否显示残疾类型选项
      disableType: "", //当前选中的残疾类型
      disableTypes: [
        //残疾类型列表
        { name: "视力残疾", value: "1" },
        { name: "听力残疾", value: "2" },
        { name: "智力残疾", value: "3" },
        { name: "其他", value: "4" },
      ],

      showHouseTypeChoice: false, //是否显示实际居住产权类型
      houseType: "", //选中的类型
      houseTypes: [
        { name: "父母或本人产权", value: "1" },
        { name: "（外）祖父母产权", value: "2" },
        { name: "租住房", value: "3" },
      ], // 实际居住产权类型列表

      showSelectOilSchoolChoice: false, //是否显示学校选项
      oilSchool: "", //当前选中的学校名称
      oilSchoolList: [], // 石油系统子女学校列表

      showArea: false, //是否显示户籍省市区选项
      areaList: areaList, // 省市区列表
      showRegionCodeChoice: false, // 是否显示区县列表
      regionCode: "", //当前选中的区县
      liveBlockLists: [], //区县列表
      showLiveStreetChoice: false, //是否显示街道列表
      liveStreet: "", //当前选中的街道
      liveStreets: [], //街道列表
      showLiveCommunityChoice: false, //是否显示小区列表
      liveCommunity: "", //当前选中的小区
      liveCommunitys: [], //小区列表

      showOilTypeChoice: false, //是否显示石油系统类型
      oilType: "", // 选中的石油系统
      oilTypes: [
        { name: "油田本部", value: "1" },
        { name: "塔石化", value: "2" },
        { name: "乙烷制乙烯", value: "3" },
        { name: "物探三处", value: "4" },
        { name: "其他", value: "5" },
      ], // 石油系统列表

      showParRlatChoice: false, //是否显示生源关系列表
      showParRlat2Choice: false, //是否显示生源关系列表
      parRlat: "", //当前选中的生源关系
      parRlat2: "",
      parRlats: [
        //生源关系列表列表
        { name: "父子（父女）", value: "1" },
        { name: "母子（母女）", value: "2" },
        { name: "祖孙", value: "3" },
        { name: "领养", value: "4" },
        { name: "其他", value: "5" },
      ],
      isSubmit: true, //是否可以提交
      alertTitle: "",
      oilShow: "", //是否显示石油...
      showWishSchool1Choice: false, //是否显示意向学校1
      showWishSchool2Choice: false, //是否显示意向学校2
      showWishSchool3Choice: false, //是否显示意向学校3
      wishSchool1: "", // 意向学校1
      wishSchool2: "",
      wishSchool3: "",
      wishSchools: [], //
      errMsg: {
        //错误文案
        errParName2: "",
        errParIdno2: "",
        errParPhone2: "",
      },
    };
  },
  computed: {
    verify() {
      return this.$store.state.verify;
    },
    oilSchoolLists() {
      const arr = [];
      if (
        this.ruleForm.oilType == "物探三处" ||
        this.ruleForm.oilType == "其他"
      ) {
        this.oilSchoolList.forEach((item) => {
          if (item.id == 8) {
            arr.push(item);
          }
        });
        return arr;
      } else {
        return this.oilSchoolList;
      }
    },
  },
  methods: {
    checkPar() {
      // 校验监护人2姓名
      const checkParNameReg = /(^.{1,10}$)/;
      if (this.ruleForm.parName2) {
        const checkParNameRes = checkParNameReg.test(this.ruleForm.parName2);
        if (!checkParNameRes) {
          this.errMsg.errParName2 = "输入长度在100以内";
        } else {
          this.errMsg.errParName2 = "";
        }
      } else {
        this.errMsg.errParName2 = "";
      }
      // 校验监护人2手机号
      const checkParPhoneReg = /^1[34578]\d{9}$/;
      if (this.ruleForm.parPhone2) {
        const checkParPhoneRes = checkParPhoneReg.test(this.ruleForm.parPhone2);
        if (!checkParPhoneRes) {
          this.errMsg.errParPhone2 = "请输入正确的手机号";
        } else {
          this.errMsg.errParPhone2 = "";
        }
      } else {
        this.errMsg.errParPhone2 = "";
      }
      // 校验监护人2身份证号
      if (this.ruleForm.regType == "reg10" || this.ruleForm.regType == "reg9") {
        this.errMsg.errParIdno2 = "";
        return false;
      }
      const checkParIdnoReg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
      if (this.ruleForm.parIdno2) {
        const checkParIdnoRes = checkParIdnoReg.test(this.ruleForm.parIdno2);
        if (!checkParIdnoRes) {
          this.errMsg.errParIdno2 = "请输入正确的身份证号";
        } else {
          this.errMsg.errParIdno2 = "";
        }
      } else {
        this.errMsg.errParIdno2 = "";
      }
    },
    submitForm(values) {
      if (
        this.errMsg.errParName2 ||
        this.errMsg.errParIdno2 ||
        this.errMsg.errParPhone2
      ) {
        return false;
      }
      if (!this.isSubmit) {
        this.$toast("请勿重复提交");
        return false;
      }
      if (this.ruleForm.healthType == "残疾") {
        if (this.ruleForm.disableType == "") {
          this.$toast("请选择残疾类型");
          return false;
        }
      }
      let params = this.ruleForm;
      // console.log(params);
      this.$store.dispatch("setUser", this.ruleForm.name);
      this.$fetch("/api/Student/SubmitStudInfo", params, "post")
        .then((data) => {
          if (data.res == 0) {
            if (this.isEditInfos) {
              Toast.success({
                message: "修改成功",
                duration: 1500,
              });
              setTimeout(() => {
                this.$router.push({ path: "/results" });
              }, 1500);
            } else {
              this.$router.push({ path: "/signup" });
            }
          } else {
            this.$toast(data.msg);
          }
        })
        .catch((error) => {
          this.$toast(error.response.data.msg);
        });
      this.isSubmit = false;
      setTimeout(() => {
        this.isSubmit = true;
      }, 3000);
      // this.$router.push({ path: "/results" });
      // this.$router.push({ path: "/signup" });
    },
    //获取学生信息数据
    getStuList() {
      this.$fetch("/api/Student/GetStudInfo", "get").then((data) => {
        if (data.res == 0) {
          // this.stuList = data.data;
          this.stuList = data.data.person;
          this.$store.dispatch("setStuList", data.data.person);
          // this.liveBlockLists = data.data.regionBlockList;
          // this.oilSchoolList = data.data.oilSchoolList;
          this.oilShow = data.data.oilShow;

          this.ruleForm.ogState = this.stuList.ogState;
          this.ruleForm.name = this.stuList.name;
          this.ruleForm.idno = this.stuList.idno;
          this.ruleForm.birth = new Date(this.stuList.birth);
          this.ruleForm.gender = this.stuList.gender;
          this.ruleForm.pwd = this.stuList.pwd;
          this.ruleForm.ogType = this.stuList.ogType || "";
          this.ruleForm.nation = this.stuList.nation || "";
          this.ruleForm.phone = this.stuList.phone;
          this.ruleForm.healthType = this.stuList.healthType || "";
          this.ruleForm.disableType = this.stuList.disableType || "";
          this.ruleForm.regType = this.stuList.regType;
          this.ruleForm.houseType = this.stuList.houseType || "";
          this.ruleForm.regionCode = this.stuList.regionCode || "";
          this.ruleForm.street = this.stuList.street || "";
          this.ruleForm.community = this.stuList.community || "";
          this.ruleForm.address = this.stuList.address || "";
          this.ruleForm.foreignAddress = this.stuList.foreignAddress || "";
          this.ruleForm.ogRegion = this.stuList.ogRegion || "";
          this.ruleForm.ogAddress = this.stuList.ogAddress || "";
          this.ruleForm.oilType = this.stuList.oilType || "";
          this.ruleForm.oilSchool = this.stuList.oilSchool || null;
          this.ruleForm.parName = this.stuList.parName || "";
          this.ruleForm.parName2 = this.stuList.parName2 || "";
          this.ruleForm.parIdno = this.stuList.parIdno || "";
          this.ruleForm.parIdno2 = this.stuList.parIdno2 || "";
          this.ruleForm.parPhone = this.stuList.parPhone || "";
          this.ruleForm.parPhone2 = this.stuList.parPhone2 || "";
          this.ruleForm.parRlat = this.stuList.parRlat || "";
          this.ruleForm.parRlat2 = this.stuList.parRlat2 || "";
          this.ruleForm.parWork = this.stuList.parWork || "";
          this.ruleForm.parWorkTel = this.stuList.parWorkTel || "";
          this.ruleForm.wishSchool1 = this.stuList.wishSchool1;
          this.ruleForm.wishSchool2 = this.stuList.wishSchool2;
          this.ruleForm.wishSchool3 = this.stuList.wishSchool3;

          this.getRegType("regType1");

          this.nation = this.stuList.nation;
          this.ogType = this.stuList.ogType;
          // 设置健康状态
          // this.healthTypes.forEach((item) => {
          //   if (item.value == this.stuList.healthType) {
          //     this.healthType = item.name;
          //   }
          // });
          this.healthType = this.stuList.healthType;
          this.disableType = this.stuList.disableType;

          // 设置产权类型
          this.houseTypes.forEach((item) => {
            if (item.value == this.stuList.houseType) {
              this.houseType = item.name;
              this.ruleForm.houseType = item.value;
            }
          });

          this.ruleForm.birth = formatDate(
            new Date(this.stuList.birth).valueOf(),
            "Y-M-D"
          );
          //设置选中的日期
          if (this.stuList.birth) {
            let birth = this.ruleForm.birth.split("-");
            this.currentDate = new Date(
              Number(birth[0]) + "/" + Number(birth[1]) + "/" + Number(birth[2])
            );
          }

          // 设置区县
          let blockLists = data.data.regionBlockList;
          this.liveBlockLists = JSON.parse(
            JSON.stringify(blockLists).replace(/regionName/g, "name")
          );
          // 回填区县
          if (this.stuList.regionCode) {
            this.liveBlockLists.forEach((item) => {
              if (item.regionCode == this.stuList.regionCode) {
                this.regionCode = item.name;
              }
            });
            // 回填街道
            if (this.stuList.street) {
              this.$fetch(
                "/api/Student/GetStreetByBlock",
                { blockCode: this.stuList.regionCode },
                "get"
              ).then((data) => {
                if (data.res == 0) {
                  // console.log(data);
                  let streetLists = data.data;
                  this.liveStreets = JSON.parse(
                    JSON.stringify(streetLists).replace(/regionName/g, "name")
                  );
                  this.liveStreets.forEach((item) => {
                    if (item.regionCode == this.stuList.street) {
                      this.liveStreet = item.name;
                    }
                  });
                } else {
                  this.$toast(data.msg);
                }
              });
              // 回填小区
              if (this.stuList.community) {
                this.$fetch(
                  "/api/Student/GetCommunityByStreet",
                  { streetCode: this.stuList.street },
                  "get"
                ).then((data) => {
                  if (data.res == 0) {
                    let communityLists = data.data;
                    this.liveCommunitys = JSON.parse(
                      JSON.stringify(communityLists).replace(
                        /regionName/g,
                        "name"
                      )
                    );
                    this.liveCommunitys.forEach((item) => {
                      if (item.regionCode == this.stuList.community) {
                        this.liveCommunity = item.name;
                      }
                    });
                  } else {
                    this.$toast(data.msg);
                  }
                });
              }
            }
            // 意向学校
            this.$fetch(
              "/api/Student/GetSchoolByBlock",
              { blockCode: this.stuList.regionCode },
              "get"
            ).then((data) => {
              // console.log(data);
              if (data.res == 0) {
                let wishSchoolList = data.data;
                this.wishSchools = JSON.parse(
                  JSON.stringify(wishSchoolList).replace(/schoolName/g, "name")
                );
                this.wishSchools.forEach((item) => {
                  if (item.id == this.stuList.wishSchool1) {
                    this.wishSchool1 = item.name;
                  }
                  if (item.id == this.stuList.wishSchool2) {
                    this.wishSchool2 = item.name;
                  }
                  if (item.id == this.stuList.wishSchool3) {
                    this.wishSchool3 = item.name;
                  }
                });
              } else {
                this.$toast(data.msg);
              }
            });
          }

          this.oilType = this.stuList.oilType;

          // 设置石油系统学校
          let oilSchool = data.data.oilSchoolList;
          // console.log(oilSchool);
          this.oilSchoolList = JSON.parse(
            JSON.stringify(oilSchool).replace(/schoolName/g, "name")
          );
          this.oilSchoolList.forEach((item) => {
            if (item.id == this.stuList.oilSchool) {
              this.oilSchool = item.name;
            }
          });

          //设置生源关系
          this.parRlat = this.stuList.parRlat;
          this.parRlat2 = this.stuList.parRlat2;
        } else {
          this.$toast(data.msg);
        }
      });
    },
    //回填出生年月和性别
    idChange() {
      if (this.stuList.regType != "reg10" && this.stuList.ogState != "0") {
        this.ruleForm.gender = this.formatId(this.ruleForm.idno, 2);
        this.ruleForm.birth = this.formatId(this.ruleForm.idno, 1);
      }
    },
    //解析身份证号码中的出生年月和性别
    formatId(card, num) {
      return getAnalysisIdCard(card, num);
    },

    //展开收起
    slideModule(val) {
      if (val == 1) {
        this.isSlide1 = !this.isSlide1;
        if (this.isSlide1 == true) {
          this.isSlide2 = false;
          this.isSlide3 = false;
          this.isSlide4 = false;
        }
      } else if (val == 2) {
        this.isSlide2 = !this.isSlide2;
        if (this.isSlide2 == true) {
          this.isSlide1 = false;
          this.isSlide3 = false;
          this.isSlide4 = false;
        }
      } else if (val == 3) {
        this.isSlide3 = !this.isSlide3;
        if (this.isSlide3 == true) {
          this.isSlide1 = false;
          this.isSlide2 = false;
          this.isSlide4 = false;
        }
      } else if (val == 4) {
        this.isSlide4 = !this.isSlide4;
        if (this.isSlide4 == true) {
          this.isSlide1 = false;
          this.isSlide2 = false;
          this.isSlide3 = false;
        }
      }
    },
    //是否显示密码
    showPwd() {
      this.isPwd = !this.isPwd;
      if (this.isPwd) {
        this.password = "password";
      } else {
        this.password = "text";
      }
    },
    //选择户籍类型
    onSelectOgType(item) {
      this.ruleForm.ogType = item.name;
      this.ogType = item.name;
      this.showOgTypeChoice = false;
    },
    //选择出生年月
    confirmBirth() {
      this.ruleForm.birth = formatDate(
        new Date(this.currentDate).valueOf(),
        "Y-M-D"
      );
      this.showBirthChoice = false;
    },
    //选择性别
    onSelectSex(item) {
      this.ruleForm.gender = item.name;
      this.showSexChoice = false;
    },
    //选择民族
    onSelectNation(item) {
      this.ruleForm.nation = item.name;
      this.nation = item.name;
      this.showNationChoice = false;
    },
    //选择健康状况
    onSelectHealthType(item) {
      this.ruleForm.healthType = item.value;
      if (item.value == "良好") {
        this.ruleForm.disableType = "";
        this.disableType = "";
      }
      this.healthType = item.name;
      this.showHealthTypeChoice = false;
    },
    //选择残疾类型
    onSelectDisableType(item) {
      this.ruleForm.disableType = item.name;
      this.disableType = item.name;
      this.showDisableTypeChoice = false;
    },
    // 选择实际居住产权类型
    onSelectHouseType(item) {
      this.ruleForm.houseType = item.value;
      this.houseType = item.name;
      this.showHouseTypeChoice = false;
    },
    // 选择石油系统
    onSelectOilType(item) {
      this.ruleForm.oilType = item.name;
      this.oilType = item.name;
      this.showOilTypeChoice = false;
      this.ruleForm.oilSchool = "";
      this.oilSchool = "";
      // if (item.value == "4" || item.value == "5") {
      //   this.ruleForm.oilSchool = "";
      //   this.oilSchool = "";
      // }
    },
    //取消石油系统选择
    onCancelOilTypeChoice() {
      this.ruleForm.oilType = "";
      this.oilType = "";
      this.oilSchool = "";
      this.ruleForm.oilSchool = 0;
    },
    //选择石油学校
    onSelectOilSchool(item) {
      this.ruleForm.oilSchool = item.id;
      // console.log(this.ruleForm.oilSchool);
      this.oilSchool = item.name;
      this.showSelectOilSchoolChoice = false;
    },
    //选择省市区
    onConfirmArea(values) {
      this.ruleForm.ogRegion = values.map((item) => item.name).join("/");
      this.showArea = false;
    },
    // 选择区县
    onSelectLiveBlock(item) {
      // console.log(item);
      this.ruleForm.regionCode = item.regionCode;
      this.regionCode = item.name;
      this.showRegionCodeChoice = false;
      this.liveStreet = "";
      this.ruleForm.street = "";
      this.liveCommunity = "";
      this.ruleForm.community = "";
      this.ruleForm.address = "";
      //获取当前居住区县下的街道 / 意向学校
      this.$fetch(
        "/api/Student/GetStreetByBlock",
        { blockCode: item.regionCode },
        "get"
      ).then((data) => {
        if (data.res == 0) {
          // console.log(data);
          let streetLists = data.data;
          this.liveStreets = JSON.parse(
            JSON.stringify(streetLists).replace(/regionName/g, "name")
          );
        } else {
          this.$toast(data.msg);
        }
      });
      this.$fetch(
        "/api/Student/GetSchoolByBlock",
        { blockCode: item.regionCode },
        "get"
      ).then((data) => {
        // console.log(data);
        if (data.res == 0) {
          let wishSchoolList = data.data;
          this.wishSchools = JSON.parse(
            JSON.stringify(wishSchoolList).replace(/schoolName/g, "name")
          );
        } else {
          this.$toast(data.msg);
        }
      });
    },
    //选择街道前判断
    onSelectStreet() {
      if (!this.regionCode) {
        this.$toast("请先选择区县");
        return false;
      }
      this.showLiveStreetChoice = true;
    },
    //选择街道
    onSelectLiveStreet(item) {
      this.ruleForm.street = item.regionCode;
      this.liveStreet = item.name;
      this.showLiveStreetChoice = false;
      //获取当前居住地街道下的小区
      this.$fetch(
        "/api/Student/GetCommunityByStreet",
        { streetCode: item.regionCode },
        "get"
      ).then((data) => {
        // console.log(data);
        if (data.res == 0) {
          let communityLists = data.data;
          this.liveCommunitys = JSON.parse(
            JSON.stringify(communityLists).replace(/regionName/g, "name")
          );
          this.liveCommunity = "";
          this.ruleForm.community = "";
          this.ruleForm.address = "";
        } else {
          this.$toast(data.msg);
        }
      });
    },
    // 选择小区前判断
    onSelectCommunity() {
      if (!this.regionCode) {
        this.$toast("请先选择区县");
        return false;
      }
      if (!this.liveStreet) {
        this.$toast("请先选择街道");
        return false;
      }
      this.showLiveCommunityChoice = true;
    },
    //选择小区
    onSelectLiveCommunity(item) {
      this.ruleForm.community = item.regionCode;
      this.liveCommunity = item.name;
      this.showLiveCommunityChoice = false;
    },
    // 选择意向学校1
    onSelectWishSchool1(item) {
      this.wishSchool1 = item.name;
      this.ruleForm.wishSchool1 = item.id;
      this.showWishSchool1Choice = false;
    },
    // 选择意向学校2
    onSelectWishSchool2(item) {
      this.wishSchool2 = item.name;
      this.ruleForm.wishSchool2 = item.id;
      this.showWishSchool2Choice = false;
    },
    // 选择意向学校3
    onSelectWishSchool3(item) {
      this.wishSchool3 = item.name;
      this.ruleForm.wishSchool3 = item.id;
      this.showWishSchool3Choice = false;
    },
    //选择生源关系
    onSelectParRlat(item) {
      this.ruleForm.parRlat = item.name;
      this.parRlat = item.name;
      this.showParRlatChoice = false;
    },
    onSelectParRlat2(item) {
      this.ruleForm.parRlat2 = item.name;
      this.parRlat2 = item.name;
      this.showParRlat2Choice = false;
    },
    //取消监护人2生源关系
    onCancelParRlat2() {
      this.ruleForm.parRlat2 = "";
      this.parRlat2 = "";
    },
    getRegType(type) {
      this.$fetch("/api/Student/GetSysCode", { type: type }, "get").then(
        (data) => {
          if (data.res == 0) {
            // console.log(data);
            data.data.forEach((item) => {
              if (item.code == this.stuList.regType) {
                this.alertTitle = item.text;
                this.regType = item.text;
              }
            });
          }
        }
      );
    },
    // 判断学生是否可修改信息、注销
    async getVerify() {
      try {
        const data = await getVerify();
        localDb.set("verify", data);
      } catch (error) {}
    },
  },
  created() {
    this.getVerify();
    //判断是不是修改页面
    if (this.$route.query.isEditInfos) {
      this.isEditInfos = true;
      this.editTitle = this.$route.query.isEditInfos;
    } else {
      this.isEditInfos = false;
    }
  },
  mounted() {
    this.getStuList();
    this.getRegType("regType1");
  },
};
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.reporting-main {
  overflow: hidden;
  padding: 0 10px;
  .iconfont {
    font-size: 38px;
  }
  .wid100 {
    /deep/ .van-field__label {
      width: 220px;
    }
  }
  .wid7 {
    /deep/ .van-field__value {
      .van-radio__label {
        margin-left: 14px;
      }
    }
    /deep/ .van-radio__icon {
      .van-icon {
        line-height: 1.15;
      }
    }
  }
  .padr {
    padding-right: 40px !important;
  }
  .form-btn {
    margin-left: -10px;
    width: 105%;
    margin-top: 31px;
    .van-button {
      height: 90px;
      font-size: 36px;
    }
  }
  .fle {
    /deep/ .van-cell__title {
      flex: 2;
    }
  }
  .fle1 {
    /deep/ .van-cell__title {
      flex: 1;
    }
  }
  .van-action-sheet {
    .van-action-sheet__gap {
      background-color: #f7f8fa;
    }
  }
}
</style>
